package com.fesine.learn.design.pattern.creational.singleton;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 示范容器单例
 * @author: fesine
 * @createTime:2019/4/13
 * @update:修改内容
 * @author: fesine
 * @updateTime:2019/4/13
 */
public class ContainerSingleton {

    private ContainerSingleton(){}

    private static Map<String, Object> singletonMap = new HashMap<>();

    public static void pubInstance(String key, Object instance) {
        if (StringUtils.isNoneBlank(key) && instance != null && !singletonMap.containsKey(key)) {
                singletonMap.put(key, instance);
        }
    }

    public static Object getInstance(String key){
        return singletonMap.get(key);
    }

}
